﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Mimoza.Common;

namespace Mimoza.Plugins.DisplaySettings
{
    abstract public class BaseConfigPlugin: Mimoza.PluginLayer.IConfigPlugin, Mimoza.PluginLayer.IPluginPolicyNotify
    {
        #region IConfigPlugin Members

        abstract public string Identity
        {
            get;
        }
        abstract public string Name
        {
            get;
        }
        abstract public string Description
        {
            get;
        }

        public bool IsHardware
        {
            get 
            { 
                return true; 
            }
        }
        public System.Drawing.Icon Icon
        {
            get 
            {
                return Resource.pluginicon;
            }
        }
        public bool IsMultiple
        {
            get 
            {
                return false;
            }
        }

        public string Serialize(object userData)
        {
            DisplayResolution pluginData = userData as DisplayResolution;
            if (pluginData == null)
            {
                Common.Logger.Log.Error(
                    "Mimoza.RdpPlugin.ConfigPlugin error: userData is not correct");
                return null;
            }

            return pluginData.Serialize();
        }
        public object Deserialize(string stringFrom)
        {
            if (stringFrom != null)
            {
                return DisplayResolution.Deserialize(stringFrom);
            }
            return new DisplayResolution();
        }

        public IEnumerable<Mimoza.GUI.IWizardPage> Pages
        {
            get 
            {
                //yield return new DisplayPlatformPage();
                yield return new DisplaySettingsConfigPage();
            }
        }
        public IEnumerable<Mimoza.GUI.IWizardPage> WizardPages
        {
            get 
            {
                yield return new DisplayPlatformPage();
                yield return new DisplaySettingsConfigPage();
            }
        }

        #endregion

        
    
        #region PluginPolicyNotify Members

        public void OnBeforePolicySave(Mimoza.ObjectLayer.Policy policy)
        {
 	        if (policy==null) return;

            DisplayResolution displayData = DisplayResolution.Deserialize(policy.Data);
            if (displayData!=null)
            {
                if (displayData.Model == ModelEnum.C36SX) policy.PluginID = Resource.PluginIdentityC36SX;
                if (displayData.Model == ModelEnum.L66) policy.PluginID = Resource.PluginIdentityL66;
                if (displayData.Model == ModelEnum.LX) policy.PluginID = Resource.PluginIdentityLX;
                if (displayData.Model == ModelEnum.VPC) policy.PluginID = Resource.PluginIdentityVirtualPC;
            }
        }

        #endregion
    }
}
